package com.awspaas.user.apps.cpq.controller;

import java.util.ArrayList;
import java.util.List;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;

public class CPQWeb {

	public String getModuleMsg( UserContext uc,String bindId, String systemBHs) {
		try {
			String[] bhs=systemBHs.split(",");
			String bhsql="";
			SDK.getBOAPI().removeByBindId("BO_EU_CPQ_PROJECT_MSG_GRIDS", bindId);
			if(bhs.length>0) {
				for (String bh : bhs) {
					if(bhsql.isEmpty()) {
						bhsql="'"+bh+"'";
					}else {
						bhsql+=",'"+bh+"'";
					}
					//将安装费用也作为系统模块放入模块清单子表中。
					bhsql+=",'AZF'";
				}
//				String moduleSql="SELECT " + 
//						"	a.XTMH,a.XTMC,m.MKMC,g.SL,g.DW," + 
//						"	m.MKBM," + 
//						"	m.MKDJ," + 
//						"	m.BBH," + 
//						"	m.VERSION  " + 
//						"FROM " + 
//						"	BO_EU_CPQ_SYSTEM_MSG a, " + 
//						"	BO_EU_CPQ_SYSTEM_MSG_GRID g, " + 
//						"	BO_EU_CPQ_MODULE_MSG m  " + 
//						"WHERE " + 
//						"	a.BINDID = g.BINDID " + 
//						"	AND g.MKBM = m.MKBM " + 
//						"	AND a.XTMH  in("+bhsql+") " + 
//						"	AND m.STATUS = '2' ";
				String moduleSql="SELECT " + 
						"	a.XTMH,a.XTMC,g.MKMC " + 				
						"FROM " + 
						"	BO_EU_CPQ_SYSTEM_MSG a, " + 
						"	BO_EU_CPQ_SYSTEM_MSG_GRID g " + 
						"WHERE " + 
						"	a.BINDID = g.BINDID " + 
						//"	AND g.MKBM = m.MKBM " + 
						"	AND a.XTMH  in("+bhsql+")";
				System.out.println(moduleSql);
				List<RowMap> maps=DBSql.getMaps(moduleSql);
				List<BO> bos=new ArrayList<BO>();
				if(maps.size()>0) {
					for (RowMap rowMap : maps) {
						BO data=new BO();
						String XTMC=rowMap.getString("XTMC");
						String MKMC=rowMap.getString("MKMC");
						//String MKBM=rowMap.getString("MKBM");
						//String MKDJ=rowMap.getString("MKDJ");
						//String BBH=rowMap.getString("BBH");
						//String VERSION=rowMap.getString("VERSION");
						String XTMH=rowMap.getString("XTMH");
						//String SL=rowMap.getString("SL");
						//String DW=rowMap.getString("DW");
						data.set("XTMC", XTMC);//系统名称
						//data.set("XDXH",MKBM );//模块编码
						//data.set("DJ", MKDJ);
						//data.set("MKBBH", BBH);
						//data.set("VERSION", VERSION);
						data.set("MKMC",MKMC );
						data.set("XTMH", XTMH);	
						//data.set("DW", DW);	
						//data.set("SL", SL);	
						bos.add(data);
					}
					
					SDK.getBOAPI().create("BO_EU_CPQ_PROJECT_MSG_GRIDS", bos, bindId, uc.getUID());
				}
				
				
			}
			   ResponseObject ro = ResponseObject.newOkResponse();
			   return ro.toString();
		} catch (Exception e) {
			throw e;
		}
		
	}

}
